// Device_M2K.cpp: implementation of the Device_M2K class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Device_M2K.h"
#include "DeviceManger.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

BOOL Device_M2K::_AfterDeviceOpen()
{
	SYZ_FUNTRACE("Device_M2K::_AfterDeviceOpen");

	USBTEL_COMM_16 tSendData(0x87, 1, 0, 0);
	USBTEL_COMM_16 tReadData;
	if(!PhoneInEcho(tSendData, tReadData, 80))
		return FALSE;
	
	m_wDeviceVer = chMAKEWORD(tReadData.Data[1], tReadData.Data[0]);
	if(!IS_M2K(m_wDeviceVer))
		return FALSE;

	TCHAR szAudioName[MAX_PATH] = _T("");
	SendMessage(CMD_DEV_GET_AUDIO_NAME, (WPARAM)szAudioName, 0);
	if(szAudioName[0] == '\0')
	{
		SYZ_TIP0("No USB Audio Device detected system need reboot");
		return FALSE;
	}

	// make a beep to report success
	_M2K_Beeper::LaunchBeep(0x419, 50, 1, 300);
	
	return TRUE;
}

BOOL Device_M2K::_BeforeDeviceClose()
{
	SYZ_FUNTRACE("Device_M2K::_BeforeDeviceClose");
	chASSERT(IsOpened());
	// make beep when exit
	_M2K_Beeper::LaunchBeep(0x419, 50, 3, 300);
	return 0;
}

BOOL Device_M2K::_Pulsation( )
{
	return _VDevicePhone16::_Pulsation();
}

void Device_M2K::TraceSendData(USBTEL_COMM_16& rTraceData)
{
	switch(rTraceData.bRequestType)
	{
	case 0x02:
//		SYZ_TRACE0("<=> Beep Data");
		break;
	case 0x03:
//		SYZ_TRACE1("<=> Beep Play [%d]", rTraceData.Data[0]);
		break;
	case 0x05:
//		SYZ_TRACE0("<=> LED Flash");
		break;
	case 0x11:
//		SYZ_TRACE0("<=> Set Beep Volum");
		break;
	default:
		_VDevicePhone16::TraceSendData(rTraceData);
	}
}

void Device_M2K::TraceReadData(USBTEL_COMM_16& rTraceData)
{
	switch(rTraceData.bRequestType)
	{
	case 0x02:
//		SYZ_TRACE0("<=> Beep Data");
		break;
	case 0x03:
//		SYZ_TRACE1("<=> Beep Play [%d]", rTraceData.Data[0]);
		break;
	case 0x05:
//		SYZ_TRACE0("<=> LED Flash");
		break;
	case 0x11:
//		SYZ_TRACE0("<=> Set Beep Volum");
		break;
	default:
		_VDevicePhone16::TraceReadData(rTraceData);
	}
}

BOOL Device_M2K::GetKeyEvent()
{
	return TRUE;
}
